package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.SysSubject;
import com.ruoyi.system.mapper.SysSubjectMapper;
import com.ruoyi.system.service.ISysSubjectService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hwh
 * @ClassName: $
 * @Description: $
 * @Date $
 * @Version 1.0
 */

@Service
@Transactional(rollbackFor = Exception.class)
public class SysSubjectServiceImpl extends ServiceImpl<SysSubjectMapper, SysSubject> implements ISysSubjectService {


    @Resource
    private SysSubjectMapper sysSubjectMapper;

    @Override
    public List<SysSubject> selectSubjectList(SysSubject sysSubject) {
        return sysSubjectMapper.selectSubjectList(sysSubject);
    }

    @Override
    public boolean addSubject(SysSubject sysSubject) {
        if (sysSubjectMapper.selectSubjectList(sysSubject).size() > 0) {
            throw new RuntimeException("该主题名称已经存在,请重新输入");
        }
        return sysSubjectMapper.addSubject(sysSubject);
    }

    @Override
    public boolean deleteSubject(Integer subjectId) {
        return sysSubjectMapper.deleteSubject(subjectId);
    }

}
